package com.lagou.tomcat;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.ServletException;

public class SpringApplication {

    public static void run(){
        //创建tomcat实例
        Tomcat tomcat = new Tomcat();
        //设置tomcat端口
        tomcat.setPort(8000);
        try {
            //设置项目文件路径
            tomcat.addWebapp("/", "D:\\");
            //启动tomcat
            tomcat.start();
            // 监听关闭端口，阻塞式。没有这一句，方法执行完会直接结束
            tomcat.getServer().await();
        } catch (LifecycleException e) {
            e.printStackTrace();
        } catch (ServletException e) {
            e.printStackTrace();
        }
    }


}
